package com.aischool.service;

import java.util.Date;
import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class AiCoursePlanService {

	/**
	 * 获取课程计划，
	 * @param class_id
	 * @param start
	 * @param end
	 * @return
	 */
	public List<Record> getCoursePlan(int class_id, Date start, Date end){
		// b.course_name, c.class_title  课程名称，课节名称
		return Db.find("SELECT a.*,b.course_id, b.course_name, b.front_cover_url, c.class_title "
				+ "FROM ai_course_plan a "
				+ "INNER JOIN ai_course b ON b.course_id = a.course_id "
				+ "LEFT JOIN ai_course_class c ON c.class_id = a.classes_id "
				+ "WHERE a.class_id = ? AND a.course_date >= ? AND a.course_date <= ? "
				+ "ORDER BY a.course_date DESC, a.plan_sort ASC",
				class_id, start, end);
	}
	
	public Record getOne(int class_id, Date start, int plan_sort){
		return Db.findFirst("SELECT a.* FROM ai_course_plan a "
				+ "WHERE a.class_id = ? AND a.course_date = ? AND a.plan_sort = ?",
				class_id, start, plan_sort);
	}
	
	public int del(int class_id, Date start, int plan_sort) {
		return Db.delete("DELETE FROM ai_course_plan "
				+ "WHERE class_id = ? AND course_date = ? AND plan_sort = ?", 
				class_id, start, plan_sort);
	}
}
